// kernel.h
//	Global variables for the Nachos kernel.
//
// Copyright (c) 1992-1996 The Regents of the University of California.
// All rights reserved.  See copyright.h for copyright notice and limitation 
// of liability and disclaimer of warranty provisions.

#ifndef KERNEL_H
#define KERNEL_H

#include "copyright.h"
#include "debug.h"
#include "utility.h"
#include "bitmap.h"
#include "thread.h"
#include "scheduler.h"
#include "interrupt.h"
#include "stats.h"
#include "alarm.h"
#include "filesys.h"
#include "machine.h"
#include "addrspace.h"

class PostOfficeInput;
class PostOfficeOutput;
class SynchConsoleInput;
class SynchConsoleOutput;
class SynchDisk;

class Kernel {
public:
	Kernel(int argc, char **argv);
	// Interpret command line arguments
	~Kernel(); // deallocate the kernel

	void Initialize(); // initialize the kernel -- separated
	// from constructor because
	// refers to "kernel" as a global

	bool saveProcessState();		// Save the Process State
									// before program switch

	bool restoreProcessState();		// Restore the Process State
									// restore registers
									// restore user program space

	void ThreadSelfTest(); // self test of threads and synchronizatin

	void ConsoleTest(); // interactive console self test

	void NetworkTest(); // interactive 2-machine network test

	void SemaphoreTest(); // producer and comsumer Test

	// These are public for notational convenience; really,
	// they're global variables used everywhere.

	Thread *currentThread; // the thread holding the CPU
	Scheduler *scheduler; // the ready list
	Interrupt *interrupt; // interrupt status
	Statistics *stats; // performance metrics
	Alarm *alarm; // the software alarm clock
	Machine *machine; // the simulated CPU
	SynchConsoleInput *synchConsoleIn;
	SynchConsoleOutput *synchConsoleOut;
	SynchDisk *synchDisk;
	Bitmap * Mmbmp; // bitmap
	FileSystem *fileSystem;
	PostOfficeInput *postOfficeIn;
	PostOfficeOutput *postOfficeOut;

	int hostName; // machine identifier
	List<Thread *> *systemThreadList; // of the System Thread List
	// I still think here should be a         ProcessList...>_<!
	//Mon Mar 28 03:06:16 CST 2011

	Stack<AddrSpace *> *userProgramSpaceStateStack;		// Stack for saving user program space
											//

private:
	bool randomSlice; // enable pseudo-random time slicing
	bool debugUserProg; // single step user program
	double reliability; // likelihood messages are dropped
	char *consoleIn; // file to read console input from
	char *consoleOut; // file to send console output to

#ifndef FILESYS_STUB
	bool formatFlag; // format the disk if this is true
#endif
};

#endif // KERNEL_H

